﻿using JustWPFControls.Converters;
using JustWPFControls.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace JustWPFControls.Controls
{
    public class JIcon:Control
    {
        public IconType Icon
        {
            get { return (IconType)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }
        public IconMode Mode
        {
            get { return (IconMode)GetValue(ModeProperty); }
            set { SetValue(ModeProperty, value); }
        }
        public ImageSource ImageSource
        {
            get { return (ImageSource)GetValue(ImageSourceProperty); }
            set { SetValue(ImageSourceProperty, value); }
        }
        public Brush Fill
        {
            get { return (Brush)GetValue(FillProperty); }
            set { SetValue(FillProperty, value); }
        }
        public Geometry Data
        {
            get { return (Geometry)GetValue(DataProperty); }
            set { SetValue(DataProperty, value); }
        }
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        public static readonly DependencyProperty TitleProperty;
        public static readonly DependencyProperty ModeProperty;
        public static readonly DependencyProperty IconProperty;
        public static readonly DependencyProperty ImageSourceProperty;
        public static readonly DependencyProperty FillProperty;
        public static readonly DependencyProperty DataProperty;
        private static void OnIconTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var iconType = (IconType)e.NewValue;
            if (d is JIcon justIcon)
            {
                if (iconType == IconType.None)
                {
                    justIcon.Data =  default!;
                }
                else
                {
                    justIcon.Data = JIconConverter.GetIcon(iconType)!;
                }
            }
        }
        static JIcon()
        {
            IconProperty = DependencyProperty.Register("Icon", typeof(IconType), typeof(JIcon), new PropertyMetadata(IconType.None,OnIconTypeChanged));
            ModeProperty = DependencyProperty.Register("Mode", typeof(IconMode), typeof(JIcon), new PropertyMetadata(IconMode.Icon));
            ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(JIcon), new PropertyMetadata(null));
            FillProperty = DependencyProperty.Register("Fill", typeof(Brush), typeof(JIcon), new PropertyMetadata(null));
            DataProperty = DependencyProperty.Register("Data", typeof(Geometry), typeof(JIcon), new PropertyMetadata(null));
            TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(JIcon), new PropertyMetadata(null));
            DefaultStyleKeyProperty.OverrideMetadata(typeof(JIcon), new FrameworkPropertyMetadata(typeof(JIcon)));
        }
    }
}
